/**
 * Class: Gravity
 *
 * Purpose: 
 *
 * Created: Jan 27, 2010 @ 9:41:06 AM
 * @author Ken Scott
 */
package org.openfantasia.ps.modifier.forces;

import org.openfantasia.ps.modifier.Force;
import org.openfantasia.ps.particle.Particle;
import org.openfantasia.util.math.DPoint3;

public class Gravity extends Force {

	private Particle center;


	public Gravity() {
	}


	public Gravity(Particle center) {
		this.center = center;
	}


	public Particle getCenter() {
		return center;
	}


	public void setCenter(Particle center) {
		this.center = center;
	}


	public void act(Particle particle) {
		DPoint3 direction = particle.getPosition().copy().sub(center.getPosition());
		double mag = direction.mag();
		direction.normalize();
		double grav = particle.getMass() * center.getMass() / (mag * mag);
		direction.scale(grav);
		particle.applyForce(direction);
	}
}
